package com.cyou.qb.common.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.cyou.qb.common.domain.AssignedWinner;

/**
 * @author zoudongchao
 *
 */
@Component
public class AssignedWinnerDao extends MysqlBaseDao {
	/**
	 * Description 
	 * @author lidongwei
	 * @return 
	 * @since 2012-10-11
	 */
	public AssignedWinner findAssignWinnerById(Integer id) {
		return this.getUniqueOne("findAssignWinnerById", id);
		
	}

	/**
	 * Description
	 * @author lidongwei
	 * @since 2012-10-11
	 */
	public int findAssignedWinnerByPassportAndAwardId(Integer awardId, String passport) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("awardId", awardId);
		params.put("passport", passport);
		
		return this.getCount("findAssignedWinnerByPassportAndAwardId", params);
		
	}

	/**
	 * <p>查找指定用户</p>
	 * @author zoudongchao
	 * @param activeId 活动id
	 * @param passport 通行证
	 * @return
	 */
	public List<AssignedWinner> findAssignedWinner(int activeId, String passport) {
		
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("activeId", activeId);
		params.put("passport", passport);

		return this.getListByEntity("findAssignedWinnerByConditions", params);
	}
	
	/**
	 * <p>根据奖品id获得指定用户列表</p>
	 * @author zoudongchao
	 * @param awardId
	 * @return 指定用户列表
	 */
	public List<AssignedWinner> findAssignedWinnerbyAwardId(int awardId){
		return this.getListByEntity("findAssignedWinnerByAwardId", awardId);
	}

	/**
	 * 获得所有有效指定中奖用户,活动结束时间小于当前
	 * @author zoudongchao
	 * @return
	 */
	public List<AssignedWinner> findAllValidAssignedWinner() {
		return this.getList("findAllValidAssignedWinner");
	}

	/**
	 * Description 获取某个奖品的指定用户中奖个数
	 * @author lidongwei
	 * @since 2012-10-11
	 */
	public int getAwardNumByAwardId(Integer awardId) {
		
		return this.getCount("getAwardNumByAwardId",awardId);
	}

	/**
	 * <p>减少指定用户可抽奖次数</p>
	 * @param activeId	活动id
	 * @param awardId	奖品id
	 * @param passport	通行证
	 */
	public void minusWinnerDrawTimes(int activeId, int awardId, String passport){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("activeId", activeId);
		params.put("awardId", awardId);
		params.put("passport", passport);

		this.update("minusWinnerDrawTimes", params);
	}
	
	/**
	 * Description 保存一个指定用户
	 * @author lidongwei
	 * @since 2012-10-11
	 */
	public int saveOneAssignedWinner(AssignedWinner assignWinner) {
		
		return this.insert("saveOneAssignedWinner", assignWinner);
		
	}

	/**
	 * Description 根据奖品id删除指定用户
	 * @author lidongwei
	 * @since 2012-10-11
	 */
	public int deleteAssignedWinnerByAwardId(Integer awardId) {
		return this.delete("deleteAssignedWinnerByAwardId", awardId);
	}

	/**
	 * Description
	 * @author lidongwei
	 * @since 2012-10-11
	 */
	public void removeOneAssignWinner(Integer id) {
		this.delete("removeOneAssignWinner", id);
		
	}
}
